
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>math --- 数学函数 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="cmath ——关于复数的数学函数" href="cmath.html" />
    <link rel="prev" title="numbers --- 数字的抽象基类" href="numbers.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/math.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="cmath.html" title="cmath ——关于复数的数学函数"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="numbers.html" title="numbers --- 数字的抽象基类"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="numeric.html" accesskey="U">数字和数学模块</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-math">
<span id="math-mathematical-functions"></span><h1><a class="reference internal" href="#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> --- 数学函数<a class="headerlink" href="#module-math" title="永久链接至标题">¶</a></h1>
<hr class="docutils" />
<p>该模块提供了对C标准定义的数学函数的访问。</p>
<p>这些函数不适用于复数；如果你需要计算复数，请使用 <a class="reference internal" href="cmath.html#module-cmath" title="cmath: Mathematical functions for complex numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code></a> 模块中的同名函数。将支持计算复数的函数区分开的目的，来自于大多数开发者并不愿意像数学家一样需要学习复数的概念。得到一个异常而不是一个复数结果使得开发者能够更早地监测到传递给这些函数的参数中包含复数，进而调查其产生的原因。</p>
<p>该模块提供了以下函数。除非另有明确说明，否则所有返回值均为浮点数。</p>
<div class="section" id="number-theoretic-and-representation-functions">
<h2>数论与表示函数<a class="headerlink" href="#number-theoretic-and-representation-functions" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="math.ceil">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">ceil</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.ceil" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的上限，即大于或者等于 <em>x</em> 的最小整数。如果 <em>x</em> 不是一个浮点数，则委托  <code class="docutils literal notranslate"><span class="pre">x.__ceil__()</span></code>, 返回一个 <a class="reference internal" href="numbers.html#numbers.Integral" title="numbers.Integral"><code class="xref py py-class docutils literal notranslate"><span class="pre">Integral</span></code></a> 类的值。</p>
</dd></dl>

<dl class="function">
<dt id="math.copysign">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">copysign</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#math.copysign" title="永久链接至目标">¶</a></dt>
<dd><p>返回一个基于 <em>x</em> 的绝对值和 <em>y</em> 的符号的浮点数。在支持带符号零的平台上，<code class="docutils literal notranslate"><span class="pre">copysign(1.0,</span> <span class="pre">-0.0)</span></code> 返回 <em>-1.0</em>.</p>
</dd></dl>

<dl class="function">
<dt id="math.fabs">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">fabs</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.fabs" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的绝对值。</p>
</dd></dl>

<dl class="function">
<dt id="math.factorial">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">factorial</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.factorial" title="永久链接至目标">¶</a></dt>
<dd><p>以一个整数返回 <em>x</em> 的阶乘。 如果 <em>x</em> 不是整数或为负数时则将引发 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>。</p>
</dd></dl>

<dl class="function">
<dt id="math.floor">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">floor</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.floor" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的向下取整，小于或等于 <em>x</em> 的最大整数。如果 <em>x</em> 不是浮点数，则委托 <code class="docutils literal notranslate"><span class="pre">x.__floor__()</span></code> ，它应返回 <a class="reference internal" href="numbers.html#numbers.Integral" title="numbers.Integral"><code class="xref py py-class docutils literal notranslate"><span class="pre">Integral</span></code></a> 值。</p>
</dd></dl>

<dl class="function">
<dt id="math.fmod">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">fmod</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#math.fmod" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <code class="docutils literal notranslate"><span class="pre">fmod(x,</span> <span class="pre">y)</span></code> ，由平台C库定义。请注意，Python表达式 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">%</span> <span class="pre">y</span></code> 可能不会返回相同的结果。C标准的目的是 <code class="docutils literal notranslate"><span class="pre">fmod(x,</span> <span class="pre">y)</span></code> 完全（数学上；到无限精度）等于 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">n*y</span></code> 对于某个整数 <em>n</em> ，使得结果具有 与 <em>x</em> 相同的符号和小于 <code class="docutils literal notranslate"><span class="pre">abs(y)</span></code> 的幅度。Python的 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">%</span> <span class="pre">y</span></code> 返回带有 <em>y</em> 符号的结果，并且可能不能完全计算浮点参数。 例如， <code class="docutils literal notranslate"><span class="pre">fmod(-1e-100,</span> <span class="pre">1e100)</span></code> 是 <code class="docutils literal notranslate"><span class="pre">-1e-100</span></code> ，但Python的 <code class="docutils literal notranslate"><span class="pre">-1e-100</span> <span class="pre">%</span> <span class="pre">1e100</span></code> 的结果是 <code class="docutils literal notranslate"><span class="pre">1e100-1e-100</span></code> ，它不能完全表示为浮点数，并且取整为令人惊讶的 <code class="docutils literal notranslate"><span class="pre">1e100</span></code> 。 出于这个原因，函数 <a class="reference internal" href="#math.fmod" title="math.fmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">fmod()</span></code></a> 在使用浮点数时通常是首选，而Python的 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">%</span> <span class="pre">y</span></code> 在使用整数时是首选。</p>
</dd></dl>

<dl class="function">
<dt id="math.frexp">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">frexp</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.frexp" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的尾数和指数作为对``(m, e)``。 <em>m</em> 是一个浮点数， <em>e</em> 是一个整数，正好是 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">==</span> <span class="pre">m</span> <span class="pre">*</span> <span class="pre">2**e</span></code> 。 如果 <em>x</em> 为零，则返回 <code class="docutils literal notranslate"><span class="pre">(0.0,</span> <span class="pre">0)</span></code> ，否则返回 <code class="docutils literal notranslate"><span class="pre">0.5</span> <span class="pre">&lt;=</span> <span class="pre">abs(m)</span> <span class="pre">&lt;</span> <span class="pre">1</span></code> 。这用于以可移植方式“分离”浮点数的内部表示。</p>
</dd></dl>

<dl class="function">
<dt id="math.fsum">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">fsum</code><span class="sig-paren">(</span><em class="sig-param">iterable</em><span class="sig-paren">)</span><a class="headerlink" href="#math.fsum" title="永久链接至目标">¶</a></dt>
<dd><p>返回迭代中的精确浮点值。通过跟踪多个中间部分和来避免精度损失:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">sum</span><span class="p">([</span><span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">])</span>
<span class="go">0.9999999999999999</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fsum</span><span class="p">([</span><span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">,</span> <span class="o">.</span><span class="mi">1</span><span class="p">])</span>
<span class="go">1.0</span>
</pre></div>
</div>
<p>该算法的准确性取决于IEEE-754算术保证和舍入模式为半偶的典型情况。在某些非Windows版本中，底层C库使用扩展精度添加，并且有时可能会使中间和加倍，导致它在最低有效位中关闭。</p>
<p>有关待进一步讨论和两种替代方法，参见 <a class="reference external" href="https://code.activestate.com/recipes/393090/">ASPN cookbook recipes for accurate floating point summation</a>。</p>
</dd></dl>

<dl class="function">
<dt id="math.gcd">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">gcd</code><span class="sig-paren">(</span><em class="sig-param">a</em>, <em class="sig-param">b</em><span class="sig-paren">)</span><a class="headerlink" href="#math.gcd" title="永久链接至目标">¶</a></dt>
<dd><p>返回整数 <em>a</em> 和 <em>b</em> 的最大公约数。如果 <em>a</em> 或 <em>b</em> 之一非零，则 <code class="docutils literal notranslate"><span class="pre">gcd(a,</span> <span class="pre">b)</span></code> 的值是能同时整除 <em>a</em> 和 <em>b</em> 的最大正整数。<code class="docutils literal notranslate"><span class="pre">gcd(0,</span> <span class="pre">0)</span></code> 返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.5 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.isclose">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">isclose</code><span class="sig-paren">(</span><em class="sig-param">a</em>, <em class="sig-param">b</em>, <em class="sig-param">*</em>, <em class="sig-param">rel_tol=1e-09</em>, <em class="sig-param">abs_tol=0.0</em><span class="sig-paren">)</span><a class="headerlink" href="#math.isclose" title="永久链接至目标">¶</a></dt>
<dd><p>若 <em>a</em> 和 <em>b</em> 的值比较接近则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>，否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
<p>根据给定的绝对和相对容差确定两个值是否被认为是接近的。</p>
<p><em>rel_tol</em> 是相对容差 —— 它是 <em>a</em> 和 <em>b</em> 之间允许的最大差值，相对于 <em>a</em> 或 <em>b</em> 的较大绝对值。例如，要设置5％的容差，请传递 <code class="docutils literal notranslate"><span class="pre">rel_tol=0.05</span></code> 。默认容差为 <code class="docutils literal notranslate"><span class="pre">1e-09</span></code>，确保两个值在大约9位十进制数字内相同。 <em>rel_tol</em> 必须大于零。</p>
<p><em>abs_tol</em> 是最小绝对容差 —— 对于接近零的比较很有用。 <em>abs_tol</em> 必须至少为零。</p>
<p>如果没有错误发生，结果将是： <code class="docutils literal notranslate"><span class="pre">abs(a-b)</span> <span class="pre">&lt;=</span> <span class="pre">max(rel_tol</span> <span class="pre">*</span> <span class="pre">max(abs(a),</span> <span class="pre">abs(b)),</span> <span class="pre">abs_tol)</span></code> 。</p>
<p>IEEE 754特殊值 <code class="docutils literal notranslate"><span class="pre">NaN</span></code> ， <code class="docutils literal notranslate"><span class="pre">inf</span></code> 和 <code class="docutils literal notranslate"><span class="pre">-inf</span></code> 将根据IEEE规则处理。具体来说， <code class="docutils literal notranslate"><span class="pre">NaN</span></code> 不被认为接近任何其他值，包括 <code class="docutils literal notranslate"><span class="pre">NaN</span></code> 。 <code class="docutils literal notranslate"><span class="pre">inf</span></code> 和 <code class="docutils literal notranslate"><span class="pre">-inf</span></code> 只被认为接近自己。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.5 新版功能.</span></p>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p><span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0485"><strong>PEP 485</strong></a> —— 用于测试近似相等的函数</p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.isfinite">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">isfinite</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.isfinite" title="永久链接至目标">¶</a></dt>
<dd><p>如果 <em>x</em> 既不是无穷大也不是NaN，则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code> ，否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code> 。 （注意 <code class="docutils literal notranslate"><span class="pre">0.0</span></code> 被认为 <em>是</em> 有限的。）</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.isinf">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">isinf</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.isinf" title="永久链接至目标">¶</a></dt>
<dd><p>如果 <em>x</em> 是正或负无穷大，则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code> ，否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code> 。</p>
</dd></dl>

<dl class="function">
<dt id="math.isnan">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">isnan</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.isnan" title="永久链接至目标">¶</a></dt>
<dd><p>如果 <em>x</em> 是 NaN（不是数字），则返回 <code class="docutils literal notranslate"><span class="pre">True</span></code> ，否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code> 。</p>
</dd></dl>

<dl class="function">
<dt id="math.ldexp">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">ldexp</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">i</em><span class="sig-paren">)</span><a class="headerlink" href="#math.ldexp" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">(2**i)</span></code> 。 这基本上是函数  <a class="reference internal" href="#math.frexp" title="math.frexp"><code class="xref py py-func docutils literal notranslate"><span class="pre">frexp()</span></code></a>  的反函数。</p>
</dd></dl>

<dl class="function">
<dt id="math.modf">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">modf</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.modf" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的小数和整数部分。两个结果都带有 <em>x</em> 的符号并且是浮点数。</p>
</dd></dl>

<dl class="function">
<dt id="math.remainder">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">remainder</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#math.remainder" title="永久链接至目标">¶</a></dt>
<dd><p>返回 IEEE 754 风格的 <em>x</em> 相对于 <em>y</em> 的余数。对于有限 <em>x</em> 和有限非零 <em>y</em> ，这是差异 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">n*y</span></code> ，其中 <code class="docutils literal notranslate"><span class="pre">n</span></code> 是与商 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span></code> 的精确值最接近的整数。如果 <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">/</span> <span class="pre">y</span></code> 恰好位于两个连续整数之间，则最近的 * even* 整数用于 <code class="docutils literal notranslate"><span class="pre">n</span></code> 。 余数 <code class="docutils literal notranslate"><span class="pre">r</span> <span class="pre">=</span> <span class="pre">remainder(x,</span> <span class="pre">y)</span></code> 因此总是满足 <code class="docutils literal notranslate"><span class="pre">abs(r)</span> <span class="pre">&lt;=</span> <span class="pre">0.5</span> <span class="pre">*</span> <span class="pre">abs(y)</span></code> 。</p>
<p>特殊情况遵循IEEE 754：特别是 <code class="docutils literal notranslate"><span class="pre">remainder(x,</span> <span class="pre">math.inf)</span></code> 对于任何有限 <em>x</em> 都是 <em>x</em> ，而 <code class="docutils literal notranslate"><span class="pre">remainder(x,</span> <span class="pre">0)</span></code> 和 <code class="docutils literal notranslate"><span class="pre">remainder(math.inf,</span> <span class="pre">x)</span></code> 引发  <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 适用于任何非NaN的 <em>x</em> 。如果余数运算的结果为零，则该零将具有与 <em>x</em> 相同的符号。</p>
<p>在使用IEEE 754二进制浮点的平台上，此操作的结果始终可以完全表示：不会引入舍入错误。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.7 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.trunc">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">trunc</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.trunc" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <a class="reference internal" href="numbers.html#numbers.Real" title="numbers.Real"><code class="xref py py-class docutils literal notranslate"><span class="pre">Real</span></code></a> 值 <em>x</em> 截断为 <a class="reference internal" href="numbers.html#numbers.Integral" title="numbers.Integral"><code class="xref py py-class docutils literal notranslate"><span class="pre">Integral</span></code></a> （通常是整数）。 委托给 <a class="reference internal" href="../reference/datamodel.html#object.__trunc__" title="object.__trunc__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">x.__trunc__()</span></code></a>。</p>
</dd></dl>

<p>注意 <a class="reference internal" href="#math.frexp" title="math.frexp"><code class="xref py py-func docutils literal notranslate"><span class="pre">frexp()</span></code></a> 和 <a class="reference internal" href="#math.modf" title="math.modf"><code class="xref py py-func docutils literal notranslate"><span class="pre">modf()</span></code></a> 具有与它们的C等价函数不同的调用/返回模式：它们采用单个参数并返回一对值，而不是通过 '输出形参' 返回它们的第二个返回参数（Python中没有这样的东西）。</p>
<p>对于 <a class="reference internal" href="#math.ceil" title="math.ceil"><code class="xref py py-func docutils literal notranslate"><span class="pre">ceil()</span></code></a> ， <a class="reference internal" href="#math.floor" title="math.floor"><code class="xref py py-func docutils literal notranslate"><span class="pre">floor()</span></code></a> 和 <a class="reference internal" href="#math.modf" title="math.modf"><code class="xref py py-func docutils literal notranslate"><span class="pre">modf()</span></code></a> 函数，请注意 <em>所有</em> 足够大的浮点数都是精确整数。Python浮点数通常不超过53位的精度（与平台C double类型相同），在这种情况下，任何浮点 <em>x</em> 与 <code class="docutils literal notranslate"><span class="pre">abs(x)</span> <span class="pre">&gt;=</span> <span class="pre">2**52</span></code> 必然没有小数位。</p>
</div>
<div class="section" id="power-and-logarithmic-functions">
<h2>幂函数与对数函数<a class="headerlink" href="#power-and-logarithmic-functions" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="math.exp">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">exp</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.exp" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>e</em> 次 <em>x</em> 幂，其中 <em>e</em> = 2.718281... 是自然对数的基数。这通常比 <code class="docutils literal notranslate"><span class="pre">math.e</span> <span class="pre">**</span> <span class="pre">x</span></code> 或 <code class="docutils literal notranslate"><span class="pre">pow(math.e,</span> <span class="pre">x)</span></code> 更精确。</p>
</dd></dl>

<dl class="function">
<dt id="math.expm1">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">expm1</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.expm1" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>e</em> 的 <em>x</em> 次幂，减1。这里 <em>e</em> 是自然对数的基数。对于小浮点数 <em>x</em> ， <code class="docutils literal notranslate"><span class="pre">exp(x)</span> <span class="pre">-</span> <span class="pre">1</span></code> 中的减法可能导致 <a class="reference external" href="https://en.wikipedia.org/wiki/Loss_of_significance">significant loss of precision</a>； <a class="reference internal" href="#math.expm1" title="math.expm1"><code class="xref py py-func docutils literal notranslate"><span class="pre">expm1()</span></code></a> 函数提供了一种将此数量计算为全精度的方法:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">exp</span><span class="p">,</span> <span class="n">expm1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">exp</span><span class="p">(</span><span class="mf">1e-5</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>  <span class="c1"># gives result accurate to 11 places</span>
<span class="go">1.0000050000069649e-05</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expm1</span><span class="p">(</span><span class="mf">1e-5</span><span class="p">)</span>    <span class="c1"># result accurate to full precision</span>
<span class="go">1.0000050000166668e-05</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.log">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">log</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="optional">[</span>, <em class="sig-param">base</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#math.log" title="永久链接至目标">¶</a></dt>
<dd><p>使用一个参数，返回 <em>x</em> 的自然对数（底为 <em>e</em> ）。</p>
<p>使用两个参数，返回给定的 <em>base</em> 的对数 <em>x</em> ，计算为 <code class="docutils literal notranslate"><span class="pre">log(x)/log(base)</span></code> 。</p>
</dd></dl>

<dl class="function">
<dt id="math.log1p">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">log1p</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.log1p" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>1+x</em> (base <em>e</em>) 的自然对数。以对于接近零的 <em>x</em> 精确的方式计算结果。</p>
</dd></dl>

<dl class="function">
<dt id="math.log2">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">log2</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.log2" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 以2为底的对数。这通常比 <code class="docutils literal notranslate"><span class="pre">log(x,</span> <span class="pre">2)</span></code> 更准确。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.3 新版功能.</span></p>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p><a class="reference internal" href="stdtypes.html#int.bit_length" title="int.bit_length"><code class="xref py py-meth docutils literal notranslate"><span class="pre">int.bit_length()</span></code></a> 返回表示二进制整数所需的位数，不包括符号和前导零。</p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.log10">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">log10</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.log10" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 底为10的对数。这通常比 <code class="docutils literal notranslate"><span class="pre">log(x,</span> <span class="pre">10)</span></code> 更准确。</p>
</dd></dl>

<dl class="function">
<dt id="math.pow">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">pow</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#math.pow" title="永久链接至目标">¶</a></dt>
<dd><p>将返回 <code class="docutils literal notranslate"><span class="pre">x</span></code> 的 <code class="docutils literal notranslate"><span class="pre">y</span></code> 次幂。特殊情况尽可能遵循C99标准的附录'F'。特别是， <code class="docutils literal notranslate"><span class="pre">pow(1.0,</span> <span class="pre">x)</span></code> 和 <code class="docutils literal notranslate"><span class="pre">pow(x,</span> <span class="pre">0.0)</span></code> 总是返回 <code class="docutils literal notranslate"><span class="pre">1.0</span></code> ，即使 <code class="docutils literal notranslate"><span class="pre">x</span></code> 是零或NaN。 如果 <code class="docutils literal notranslate"><span class="pre">x</span></code> 和 <code class="docutils literal notranslate"><span class="pre">y</span></code> 都是有限的， <code class="docutils literal notranslate"><span class="pre">x</span></code> 是负数， <code class="docutils literal notranslate"><span class="pre">y</span></code> 不是整数那么 <code class="docutils literal notranslate"><span class="pre">pow(x,</span> <span class="pre">y)</span></code> 是未定义的，并且引发 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 。</p>
<p>与内置的 <code class="docutils literal notranslate"><span class="pre">**</span></code> 运算符不同， <a class="reference internal" href="#math.pow" title="math.pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.pow()</span></code></a> 将其参数转换为 <a class="reference internal" href="functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> 类型。使用 <code class="docutils literal notranslate"><span class="pre">**</span></code> 或内置的 <a class="reference internal" href="functions.html#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a> 函数来计算精确的整数幂。</p>
</dd></dl>

<dl class="function">
<dt id="math.sqrt">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">sqrt</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.sqrt" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的平方根。</p>
</dd></dl>

</div>
<div class="section" id="trigonometric-functions">
<h2>三角函数<a class="headerlink" href="#trigonometric-functions" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="math.acos">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">acos</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.acos" title="永久链接至目标">¶</a></dt>
<dd><p>以弧度为单位返回 <em>x</em> 的反余弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.asin">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">asin</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.asin" title="永久链接至目标">¶</a></dt>
<dd><p>以弧度为单位返回 <em>x</em> 的反正弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.atan">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">atan</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.atan" title="永久链接至目标">¶</a></dt>
<dd><p>以弧度为单位返回 <em>x</em> 的反正切值。</p>
</dd></dl>

<dl class="function">
<dt id="math.atan2">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">atan2</code><span class="sig-paren">(</span><em class="sig-param">y</em>, <em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.atan2" title="永久链接至目标">¶</a></dt>
<dd><p>以弧度为单位返回 <code class="docutils literal notranslate"><span class="pre">atan(y</span> <span class="pre">/</span> <span class="pre">x)</span></code> 。结果是在 <code class="docutils literal notranslate"><span class="pre">-pi</span></code> 和 <code class="docutils literal notranslate"><span class="pre">pi</span></code> 之间。从原点到点 <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y)</span></code>  的平面矢量使该角度与正X轴成正比。 <a class="reference internal" href="#math.atan2" title="math.atan2"><code class="xref py py-func docutils literal notranslate"><span class="pre">atan2()</span></code></a> 的点的两个输入的符号都是已知的，因此它可以计算角度的正确象限。 例如， <code class="docutils literal notranslate"><span class="pre">atan(1)</span></code> 和 <code class="docutils literal notranslate"><span class="pre">atan2(1,</span> <span class="pre">1)</span></code>  都是 <code class="docutils literal notranslate"><span class="pre">pi/4</span></code> ，但 <code class="docutils literal notranslate"><span class="pre">atan2(-1,</span> <span class="pre">-1)</span></code> 是 <code class="docutils literal notranslate"><span class="pre">-3*pi/4</span></code> 。</p>
</dd></dl>

<dl class="function">
<dt id="math.cos">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">cos</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.cos" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 弧度的余弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.hypot">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">hypot</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#math.hypot" title="永久链接至目标">¶</a></dt>
<dd><p>返回欧几里德范数， <code class="docutils literal notranslate"><span class="pre">sqrt(x*x</span> <span class="pre">+</span> <span class="pre">y*y)</span></code> 。 这是从原点到点 <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y)</span></code> 的向量长度。</p>
</dd></dl>

<dl class="function">
<dt id="math.sin">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">sin</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.sin" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 弧度的正弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.tan">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">tan</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.tan" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 弧度的正切值。</p>
</dd></dl>

</div>
<div class="section" id="angular-conversion">
<h2>角度转换<a class="headerlink" href="#angular-conversion" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="math.degrees">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">degrees</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.degrees" title="永久链接至目标">¶</a></dt>
<dd><p>将角度 <em>x</em> 从弧度转换为度数。</p>
</dd></dl>

<dl class="function">
<dt id="math.radians">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">radians</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.radians" title="永久链接至目标">¶</a></dt>
<dd><p>将角度 <em>x</em> 从度数转换为弧度。</p>
</dd></dl>

</div>
<div class="section" id="hyperbolic-functions">
<h2>双曲函数<a class="headerlink" href="#hyperbolic-functions" title="永久链接至标题">¶</a></h2>
<p><a class="reference external" href="https://en.wikipedia.org/wiki/Hyperbolic_function">双曲函数</a> 是基于双曲线而非圆来对三角函数进行模拟。</p>
<dl class="function">
<dt id="math.acosh">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">acosh</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.acosh" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的反双曲余弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.asinh">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">asinh</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.asinh" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的反双曲正弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.atanh">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">atanh</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.atanh" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的反双曲正切值。</p>
</dd></dl>

<dl class="function">
<dt id="math.cosh">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">cosh</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.cosh" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的双曲余弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.sinh">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">sinh</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.sinh" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的双曲正弦值。</p>
</dd></dl>

<dl class="function">
<dt id="math.tanh">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">tanh</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.tanh" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 的双曲正切值。</p>
</dd></dl>

</div>
<div class="section" id="special-functions">
<h2>特殊函数<a class="headerlink" href="#special-functions" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="math.erf">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">erf</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.erf" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 处的 <a class="reference external" href="https://en.wikipedia.org/wiki/Error_function">error function</a> 。</p>
<p><a class="reference internal" href="#math.erf" title="math.erf"><code class="xref py py-func docutils literal notranslate"><span class="pre">erf()</span></code></a> 函数可用于计算传统的统计函数，如 <a class="reference external" href="https://en.wikipedia.org/wiki/Normal_distribution#Cumulative_distribution_function">累积标准正态分布</a></p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">phi</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="s1">&#39;Cumulative distribution function for the standard normal distribution&#39;</span>
    <span class="k">return</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">+</span> <span class="n">erf</span><span class="p">(</span><span class="n">x</span> <span class="o">/</span> <span class="n">sqrt</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)))</span> <span class="o">/</span> <span class="mf">2.0</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.erfc">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">erfc</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.erfc" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 处的互补误差函数。 <a class="reference external" href="https://en.wikipedia.org/wiki/Error_function">互补错误函数</a> 定义为 <code class="docutils literal notranslate"><span class="pre">1.0</span> <span class="pre">-</span> <span class="pre">erf(x)</span></code>。 它用于 <em>x</em> 的大值，从其中减去一个会导致 <a class="reference external" href="https://en.wikipedia.org/wiki/Loss_of_significance">有效位数损失</a>。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.gamma">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">gamma</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.gamma" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>x</em> 处的 <a class="reference external" href="https://en.wikipedia.org/wiki/Gamma_function">伽马函数</a> 值。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="math.lgamma">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">lgamma</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#math.lgamma" title="永久链接至目标">¶</a></dt>
<dd><p>返回Gamma函数在 <em>x</em> 绝对值的自然对数。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.2 新版功能.</span></p>
</div>
</dd></dl>

</div>
<div class="section" id="constants">
<h2>常量<a class="headerlink" href="#constants" title="永久链接至标题">¶</a></h2>
<dl class="data">
<dt id="math.pi">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">pi</code><a class="headerlink" href="#math.pi" title="永久链接至目标">¶</a></dt>
<dd><p>数学常数 <em>π</em> = 3.141592...，精确到可用精度。</p>
</dd></dl>

<dl class="data">
<dt id="math.e">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">e</code><a class="headerlink" href="#math.e" title="永久链接至目标">¶</a></dt>
<dd><p>数学常数 <em>e</em> = 2.718281...，精确到可用精度。</p>
</dd></dl>

<dl class="data">
<dt id="math.tau">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">tau</code><a class="headerlink" href="#math.tau" title="永久链接至目标">¶</a></dt>
<dd><p>数学常数 <em>τ</em> = 6.283185...，精确到可用精度。Tau 是一个圆周常数，等于 2<em>π</em>，圆的周长与半径之比。更多关于 Tau 的信息可参考 Vi Hart 的视频 <a class="reference external" href="https://www.youtube.com/watch?v=jG7vhMMXagQ">Pi is (still) Wrong</a>。吃两倍多的派来庆祝 <a class="reference external" href="https://tauday.com/">Tau 日</a> 吧！</p>
<div class="versionadded">
<p><span class="versionmodified added">3.6 新版功能.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="math.inf">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">inf</code><a class="headerlink" href="#math.inf" title="永久链接至目标">¶</a></dt>
<dd><p>浮点正无穷大。 （对于负无穷大，使用 <code class="docutils literal notranslate"><span class="pre">-math.inf</span></code> 。）相当于``float('inf')`` 的输出。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.5 新版功能.</span></p>
</div>
</dd></dl>

<dl class="data">
<dt id="math.nan">
<code class="sig-prename descclassname">math.</code><code class="sig-name descname">nan</code><a class="headerlink" href="#math.nan" title="永久链接至目标">¶</a></dt>
<dd><p>浮点“非数字”（NaN）值。 相当于 <code class="docutils literal notranslate"><span class="pre">float('nan')</span></code> 的输出。</p>
<div class="versionadded">
<p><span class="versionmodified added">3.5 新版功能.</span></p>
</div>
</dd></dl>

<div class="impl-detail compound">
<p class="compound-first"><strong>CPython implementation detail:</strong> <a class="reference internal" href="#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> 模块主要包含围绕平台C数学库函数的简单包装器。特殊情况下的行为在适当情况下遵循C99标准的附录F。当前的实现将引发 <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> 用于无效操作，如 <code class="docutils literal notranslate"><span class="pre">sqrt(-1.0)</span></code> 或 <code class="docutils literal notranslate"><span class="pre">log(0.0)</span></code> （其中C99附件F建议发出无效操作信号或被零除）， 和 <a class="reference internal" href="exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> 用于溢出的结果（例如， <code class="docutils literal notranslate"><span class="pre">exp(1000.0)</span></code> ）。除非一个或多个输入参数是NaN，否则不会从上述任何函数返回NaN；在这种情况下，大多数函数将返回一个NaN，但是（再次遵循C99附件F）这个规则有一些例外，例如 <code class="docutils literal notranslate"><span class="pre">pow(float('nan'),</span> <span class="pre">0.0)</span></code> 或 <code class="docutils literal notranslate"><span class="pre">hypot(float('nan'),</span> <span class="pre">float('inf'))</span></code> 。</p>
<p class="compound-last">请注意，Python不会将显式NaN与静默NaN区分开来，并且显式NaN的行为仍未明确。典型的行为是将所有NaN视为静默的。</p>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><a class="reference internal" href="cmath.html#module-cmath" title="cmath: Mathematical functions for complex numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code></a> 模块</dt><dd><p>这里很多函数的复数版本。</p>
</dd>
</dl>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">目录</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code> --- 数学函数</a><ul>
<li><a class="reference internal" href="#number-theoretic-and-representation-functions">数论与表示函数</a></li>
<li><a class="reference internal" href="#power-and-logarithmic-functions">幂函数与对数函数</a></li>
<li><a class="reference internal" href="#trigonometric-functions">三角函数</a></li>
<li><a class="reference internal" href="#angular-conversion">角度转换</a></li>
<li><a class="reference internal" href="#hyperbolic-functions">双曲函数</a></li>
<li><a class="reference internal" href="#special-functions">特殊函数</a></li>
<li><a class="reference internal" href="#constants">常量</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="numbers.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">numbers</span></code> --- 数字的抽象基类</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="cmath.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code> ——关于复数的数学函数</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/math.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="cmath.html" title="cmath ——关于复数的数学函数"
             >下一页</a> |</li>
        <li class="right" >
          <a href="numbers.html" title="numbers --- 数字的抽象基类"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="numeric.html" >数字和数学模块</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>